package com.powergame.model;

import com.jme3.asset.AssetManager;
import com.jme3.material.Material;
import com.jme3.math.Vector3f;
import com.jme3.scene.Geometry;
import com.jme3.scene.Spatial;
import com.jme3.scene.shape.Box;
import com.powergame.controls.PieceControl;

/**
 * PiecesFactory.java
 *
 * Fabrique de pièce de jeu 
 *
 * @author ToF
 */
public class PiecesFactory {
    
    private AssetManager assetManager = null;
    
    private Equipe equipe = null;
    
    public PiecesFactory(Equipe equipe){
        this.equipe = equipe;
    }
    
    public PiecesFactory(Equipe equipe, AssetManager assetManager){
        this.equipe = equipe;
        this.assetManager = assetManager;
    }

    public AssetManager getAssetManager() {
        return assetManager;
    }

    public void setAssetManager(AssetManager assetManager) {
        this.assetManager = assetManager;
    }

    public Equipe getEquipe() {
        return equipe;
    }

    public void setEquipe(Equipe equipe) {
        this.equipe = equipe;
    }
    
    public Piece createSoldat() {
        
        Piece soldat = new Piece(null, "Soldat", TypePiece.PIECE_SOLDAT, equipe);
        
        Geometry g = new Geometry("soldat", new Box(Vector3f.ZERO, 2f, 5f, 2f));
        soldat.setSpatial(g);
        
        g.addControl(new PieceControl(soldat));
        
        Material mat = new Material(assetManager,  "Common/MatDefs/Light/Lighting.j3md"); // ... specify .j3md file to use (illuminated).
        mat.setBoolean("UseMaterialColors",true);  // Set some parameters, e.g. blue.
        mat.setColor("Ambient", equipe.getCouleur());   // ... color of this object
        mat.setColor("Diffuse", equipe.getCouleur());   // ... color of light being reflected
        g.setMaterial(mat);               // Use new material on this Geometry.
        
        return soldat;
    }
    
    public Piece createTank(){
        Piece tank = new Piece(null, "Tank", TypePiece.PIECE_TANK, equipe);
        
        Geometry g = new Geometry("tank", new Box(Vector3f.ZERO, 2f, 5f, 2f));
        tank.setSpatial(g);
        
        g.addControl(new PieceControl(tank));
        
        Material mat = new Material(assetManager,  "Common/MatDefs/Light/Lighting.j3md"); // ... specify .j3md file to use (illuminated).
        mat.setBoolean("UseMaterialColors",true);  // Set some parameters, e.g. blue.
        mat.setColor("Ambient", equipe.getCouleur());   // ... color of this object
        mat.setColor("Diffuse", equipe.getCouleur());   // ... color of light being reflected
        g.setMaterial(mat);               // Use new material on this Geometry.
        
        return tank;
    }
    
    public Piece createChasseur(){
        Piece chasseur = new Piece(null, "Chasseur", TypePiece.PIECE_CHASSEUR, equipe);
        
        Geometry g = new Geometry("chasseur", new Box(Vector3f.ZERO, 2f, 5f, 2f));
        chasseur.setSpatial(g);
        
        g.addControl(new PieceControl(chasseur));
        
        Material mat = new Material(assetManager,  "Common/MatDefs/Light/Lighting.j3md"); // ... specify .j3md file to use (illuminated).
        mat.setBoolean("UseMaterialColors",true);  // Set some parameters, e.g. blue.
        mat.setColor("Ambient", equipe.getCouleur());   // ... color of this object
        mat.setColor("Diffuse", equipe.getCouleur());   // ... color of light being reflected
        g.setMaterial(mat);               // Use new material on this Geometry.
        
        return chasseur;
    }
    
    public Piece createDestroyer(){
        
        Piece destroyer = new Piece(null, "Destroyer", TypePiece.PIECE_DESTROYER, equipe);
        Geometry g = new Geometry("soldat", new Box(Vector3f.ZERO, 2f, 2f, 10f));
        destroyer.setSpatial(g);
        
        g.addControl(new PieceControl(destroyer));
        
        Material mat = new Material(assetManager,  "Common/MatDefs/Light/Lighting.j3md"); // ... specify .j3md file to use (illuminated).
        mat.setBoolean("UseMaterialColors",true);  // Set some parameters, e.g. blue.
        mat.setColor("Ambient", equipe.getCouleur());   // ... color of this object
        mat.setColor("Diffuse", equipe.getCouleur());   // ... color of light being reflected
        g.setMaterial(mat);              
        
        return destroyer;
    }
}
